﻿using System;
using System.Collections.Generic;
using System.Text;
using Mang24k99.Model.COMM;
using Common;

namespace Mang24k99.Business.COMM
{
    public static class BKtCommCodeType 
    {
        /// <summary>
        ///新增一条记录
        /// </summary>
        /// <param name="codetype"></param>
        /// <returns></returns>
        public static bool Save(MKtCommCodeType codetype)
        {
            try
            {
                MKtCommCodeType.Create(codetype);
                return true;
            }
            catch (System.Exception e)
            {
                return false;
            }
        }
        /// <summary>
        /// 修改一条记录
        /// </summary>
        /// <param name="codetype"></param>
        /// <returns></returns>
        public static bool Update(MKtCommCodeType codetype)
        {
            try
            {
                MKtCommCodeType.Update(codetype);
                return true;
            }
            catch (System.Exception e)
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="codetype"></param>
        /// <returns></returns>
        public static bool Delete(MKtCommCodeType codetype)
        {
            try
            {
                MKtCommCodeType.Delete(codetype);
                return true;
            }
            catch (System.Exception e)
            {
                return false;
            }
        }

        /// <summary>
        /// 验证编码是否有效
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string CodeValidate(string code)
        {
            string strvalidate = string.Empty;
            if (code == "")
            {
                strvalidate = "代码编码不能为空";
                return strvalidate;
            }
            if (PageValidate.IsNumber(code) == false)
            {
                strvalidate = "代码编码必须为数字类型！";
                return strvalidate;
            }

            int intReturn = MKtCommCodeType.SelectByProperty("TYPE_CODE", Int32.Parse(code));
            if (intReturn != 0)
            {
                strvalidate = "代码编码不能重复！";
                return strvalidate;
            }

            strvalidate = "success";
            return strvalidate;
        }
        /// <summary>
        /// 验证编码名称是否有效
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string NameValidate(string codename)
        {
            string strvalidate = string.Empty;
            if (codename == "")
            {
                strvalidate = "编码名称不能为空";
                return strvalidate;
            }
            int intReturn = MKtCommCodeType.SelectByProperty("TYPE_NAME", codename);
            if (intReturn != 0)
            {
                strvalidate = "编码名称不能重复！";
                return strvalidate;
            }

            strvalidate = "success";
            return strvalidate;
        }

        /// <summary>
        /// 返回所有可用的记录条数
        /// </summary>
        /// <returns></returns>
        public static int GetCount()
        {
            string where = "where 1=1";
            return (int)MKtCommCodeType.GetCount(where);
        }
        /// <summary>
        /// 返回符合条件的记录集合
        /// </summary>
        /// <param name="start"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public static IList<MKtCommCodeType> FindALLSliced(int start, int max)
        {
            string where = "order by ID";
            return (IList<MKtCommCodeType>)MKtCommCodeType.FindALLSliced(start, max, where);
        }
    }
}
